package com.lirh;

import com.lirh.poi.PreTestReadXlsToNode;
import com.lirh.pojo.MultiTree;

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        JFrame frame = new JFrame("bot流程测试");
        // frame.setLayout(new BorderLayout() );
        //    frame.add(new JButton("hello"),BorderLayout.NORTH);


        //   frame.setLayout(new BorderLayout() );

        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
        // panel.setLayout(new GridLayout(7,1,1,5));
        panel.setBackground(Color.white);
        //pid输入框
        panel.add(new JLabel("PID:"));
        JTextField pidField = new JTextField(50);
        pidField.setFont(new Font("楷体",Font.BOLD,16));
//        pidField.setText("请输入机器人的PId");
        pidField.setText("914010720");
        panel.add(pidField);
        // 文件输入框
        panel.add(new JLabel("Excel路径:"));
        JTextField excelField = new JTextField(50);
        excelField.setFont(new Font("楷体",Font.BOLD,16));
        excelField.setText("C:\\Users\\AIspeech\\Desktop\\盒子测试10327107.xls");
        panel.add(excelField);
        //sheet输入框
        panel.add(new JLabel("Sheet:    "));
        JTextField sheetField = new JTextField(50);
        sheetField.setFont(new Font("楷体",Font.BOLD,16));
        sheetField.setText("请输入Sheet");
        panel.add(sheetField);
        //添加按钮
        JButton button1 = new JButton("用例");
        panel.add(button1);
        JButton button2 = new JButton("用例+请求");
        panel.add(button2);
        JButton button3 = new JButton("请求");
        panel.add(button3);
        // JTextArea textArea = new JTextArea(28, 40);
//        panel.add(textArea);
        JTextArea textArea = new JTextArea(15,40);
        textArea.setFont(new Font("楷体",Font.BOLD,20));
        textArea.append("注意：\n1.文件仅支持xls格式，未做xlsx兼容。\n2.请求的地址为http://dm-runtime-alpha.\n  talkinggenie.com/callcenter/nlu。\n3.有建议或需求请联系我。");
        JScrollPane jsp = new JScrollPane(textArea);
        // textArea.setColumns(20);
        panel.add(jsp);

       // 用例
        button1.addActionListener((e)->{
                    textArea.setText("");
                    MultiTree multiTree = new MultiTree();
                    //TestReadXlsToNode testReadXlsToNode = new Pre();
                    PreTestReadXlsToNode testReadXlsToNode = new PreTestReadXlsToNode();
            java.util.List<String> path1 = null;
            try {
                path1 = multiTree.listAllPathByRecursion(excelField.getText().trim(),sheetField.getText().trim());
                System.out.println(path1);
                textArea.append(path1.toString());
                testReadXlsToNode.writeResultToXls2222(path1,excelField.getText().trim());
            } catch (Exception e1) {
                e1.printStackTrace();
            }



                }
        );
        //用例+请求
        button2.addActionListener((e)->{
                    textArea.setText("");
                    MultiTree multiTree = new MultiTree();
                    //TestReadXlsToNode testReadXlsToNode = new Pre();
                    PreTestReadXlsToNode testReadXlsToNode = new PreTestReadXlsToNode();
            List<String> path1 = null;
            try {
                path1 = multiTree.listAllPathByRecursion2(excelField.getText().trim(),sheetField.getText().trim());
                System.out.println(path1);
                textArea.append(path1.toString());
                testReadXlsToNode.writeResultToXls2(path1,excelField.getText().trim(),pidField.getText().trim(),textArea);
            } catch (Exception e1) {
                e1.printStackTrace();
            }


                }
        );
        //请求
        button3.addActionListener((e)->{
                    textArea.setText("");
                    try {
                        new PreTestReadXlsToNode().writeResultToXls11112(excelField.getText().trim(),pidField.getText().trim(),textArea);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }

                }
        );


        frame.add(panel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(0,0,500,640);
        frame.setVisible(true);
    }




}
